package com.mvd.app.upload;

import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.mvd.app.R;
import com.mvd.app.ac2020.MyVideoAdapter;
import com.mvd.app.activity.BaseActivity;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.VideoUploadModel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MyUploadVideoActivity extends BaseActivity {

    @BindView(R.id.ac_my_video_fab)
    FloatingActionButton acMyVideoFab;
    @BindView(R.id.ac_my_video_listview)
    ListView acMyVideoListview;

    MyUploadVideoActivity instances = null;
    List<VideoUploadModel> VideoUploadModelList = new ArrayList<>();
    MyVideoAdapter myVideoAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_upload_video);
        ButterKnife.bind(this);
        setBackBtn();
        setTopTitle("录像列表");
        instances = this;

    }

    @Override
    protected void onResume() {
        super.onResume();
        refresh();
    }

    /**
     * Refresh.
     * 刷新数据库信息
     */
    void refresh() {
        CommonUtils.showLoadingDialog(instances, "加载中...");
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                initAdapterData();
                CommonUtils.hideLoadingDialog(instances);
            }
        }, 1300);//后执行Runnable中的run方法
    }

    void initAdapterData() {
        VideoUploadModelList = new ArrayList<>();
        VideoUploadModelList = VideoUploadModel.find(VideoUploadModel.class, "statement=?", "0");
        if (VideoUploadModelList != null && VideoUploadModelList.size() > 0) {
            for (int i = 0; i < VideoUploadModelList.size(); i++) {
                UtilsLog.e("VideoUploadModelList==" + i + "===" + VideoUploadModelList.get(i));
            }
            myVideoAdapter = new MyVideoAdapter(instances, VideoUploadModelList, "");

            //创建布局管理
//        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//        acMyVideoListview.setLayoutManager(layoutManager);

            acMyVideoListview.setAdapter(myVideoAdapter);
            acMyVideoListview.setVisibility(View.VISIBLE);
        } else {
            acMyVideoListview.setVisibility(View.GONE);
            Toast.makeText(instances,"录像已经全部上传",Toast.LENGTH_LONG).show();
//            showDialog(instances, "录像已经全部上传");
        }
//        VideoUploadModelList = VideoUploadModel.listAll(VideoUploadModel.class);
//        if (VideoUploadModelList != null && VideoUploadModelList.size() > 0) {
//            for (int i = 0; i < VideoUploadModelList.size(); i++) {
//                UtilsLog.e("saveDataModelList==" + i + "===" + VideoUploadModelList.get(i));
//            }
//        }

    }

    @OnClick(R.id.ac_my_video_fab)
    public void onViewClicked() {
        refresh();
    }
}
